package com.yunhe.inspect.controller.wechat;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.inspect.domain.DataInspectOrder;
import com.yunhe.inspect.domain.RectificationSheet;
import com.yunhe.inspect.model.*;
import com.yunhe.inspect.service.DataInspectOrderService;
import com.yunhe.inspect.service.RectificationSheetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description 巡检工单表
 * @author misty
 * @date 2021-11-10
 */
@Api(value = "DataInspectOrder", description = "微信端巡检工单表管理", tags = {"微信端巡检工单"})
@RestController
@RequestMapping(value = "/wechatDataInspectOrder")
public class WechatDataInspectOrderController {

    @Autowired
    private DataInspectOrderService dataInspectOrderService;

    @Autowired
    private RectificationSheetService rectificationSheetService;

    /**
     * 提交整改单
     * @author misty
     * @date 2021/11/10
     **/
    @ApiOperation("提交整改单")
    @PostMapping("/updateRectificationSheet")
    public ResponseEntity<ResultObject> updateRectificationSheet(@RequestBody RectificationSheet rectificationSheet) throws ArgumentErrorException {
        rectificationSheetService.updateRectificationSheetByPrimaryKeySelective(rectificationSheet);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("微信查看历史整改记录")
    @GetMapping("/getRectificationHistory")
    public ResponseEntity<ResultObject<List<RectificationHistoryVO>>> getRectificationHistory(@RequestParam(value = "inspectOrderId",required = true) int inspectOrderId){
        return new ResponseEntity<>(new ResultObject(dataInspectOrderService.getRectificationHistory(inspectOrderId)),HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/11/10
     **/
    @ApiOperation("根据id查询巡检工单表")
    @GetMapping("/findDataInspectOrderById")
    public ResponseEntity<ResultObject<DataInspectOrderForWechatDTO>> findDataInspectOrderById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataInspectOrderService.findDataInspectOrderByIdForWechat(id)),HttpStatus.OK);
    }

    @ApiOperation("查询巡检工单列表")
    @PostMapping("/findDataInspectOrder")
    public ResponseEntity<ResultObject<List<DataInspectOrder>>> findDataInspectOrder(@RequestBody InspectOrderWechatCondition inspectOrderWechatCondition) throws ArgumentErrorException {
        PageResult pageResult = dataInspectOrderService.getDataInspectOrderByConditionForWechat(inspectOrderWechatCondition);
        return new ResponseEntity(new ResultObject<>(pageResult), HttpStatus.OK);
    }


}